#include "Deck.h"

// Initialize the deck
void Initialize(deck& d)
{

	int k = 0;
	card c;
	const int KINDS = 4;
	const int NB_CARD_OF_KIND = 13;
	const int ACE = 0;
	d.nbCardToDistribute = 51;

	// Initialisation of the deck with all the cards parameters.
	for (int i = 0; i < KINDS; i++)
	{
		for (int j = 0; j < NB_CARD_OF_KIND; j++)
		{
			// Putting parameters in cards.
			c.figure = CARD_FIGURES[j];
			c.kind = CARD_KINDS[i];
			c.value = j + 1;
			d.cards[k] = c;
			k++;
		}
	}
}

//Display function of the deck
void Display(const deck& d)
{
	//Display of each of the cards in the deck.
	for (int i = 0; i < NB_DECK_CARDS; i++)
	{
		Display(d.cards[i], i, CARD_WIDTH_VISUAL);
	}
}

//Shuffling function.
void Shuffle(deck& d)
{
	int k;
	int l;
	card tempCard;
	const int SHUFFLE_TIME = 3;

	// This "for" is a 5 seconds timer using the CPUs clock.
	for (auto runUntil = std::chrono::system_clock::now() + std::chrono::seconds(SHUFFLE_TIME);
		 std::chrono::system_clock::now() < runUntil;)
	{
		// Randomization of all cards in deck.
		k = rand() % NB_DECK_CARDS;
		l = rand() % NB_DECK_CARDS;

		// Switching the index of each random results to do the shuffle.
		tempCard = d.cards[k];
		d.cards[k] = d.cards[l];
		d.cards[l] = tempCard;

	}
}